package com.fyzk.utils;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.alipay.sdk.app.PayTask;

import java.util.Map;

/**
 * 支付工具类
 */
public class PaymentUtil {

    public static final String TAG = "PaymentUtil";
    public static final int ALI_PAY = 12;

    private PaymentUtil() {
    }

    public static PaymentUtil getInstance() {
        return new PaymentUtil();
    }

    /**
     * 支付宝支付
     *
     * @param activity
     * @param orderInfo
     * @param handler
     */
    public void aliPay(final Activity activity, final String orderInfo, final Handler handler) {
        new Thread(() -> {
            Log.e(TAG, orderInfo);
            PayTask aliPay = new PayTask(activity);
            Map<String, String> result = aliPay.payV2(orderInfo, true);

            Message msg = new Message();
            msg.what = ALI_PAY;
            msg.obj = result;
            handler.sendMessage(msg);
        }).start();
    }

//    public void wxPay(Context context, @WXType int payType, JSONObject json) throws Exception {
//        IWXAPI api = WXAPIFactory.createWXAPI(context, Constants.WX_APP_ID);
//        //将app注册到微信
//        api.registerApp(Constants.WX_APP_ID);
//        WXPayEntryActivity.type = payType;
//        LogUtil.e(TAG, json.toString());
//        if (api.isWXAppInstalled() && api.getWXAppSupportAPI() >= Build.PAY_SUPPORTED_SDK_INT) {
//            PayReq request = new PayReq();
//            request.appId = json.getString("appid");
//            request.partnerId = json.getString("partnerid");
//            request.nonceStr = json.getString("noncestr");
//            request.timeStamp = json.getString("timestamp");
//            request.sign = json.getString("sign");
//            request.prepayId = json.getString("prepayid");
//            request.packageValue = json.getString("package");
//
//            api.sendReq(request);
//        } else {//未安装微信或该版本微信不支持微信支付
//            new IphoneDialogBuilder(context)
//                    .setTitle("提示")
//                    .setMessage("您未安装微信或者该版本微信暂不支持微信支付!")
//                    .setPositiveButton("我知道了", (dialog, i) -> dialog.dismiss())
//                    .show();
//        }
//    }
}
